import type { VbenFormSchema } from '#/adapter/form';
import type { VxeTableGridOptions } from '#/adapter/vxe-table';
import type { BookingResourceConstraintCheckApi } from '#/api/spa/booking/resourceconstraintcheck';

import { DICT_SPA_TYPE } from '#/utils/dictSpa';
import { z } from '#/adapter/form';
import { DICT_TYPE, getDictOptions, getRangePickerDefaultProps } from '#/utils';

/** 新增/修改的表单 */
export function useFormSchema(): VbenFormSchema[] {
  return [
    {
      fieldName: 'id',
      component: 'Input',
      dependencies: {
        triggerFields: [''],
        show: () => false,
      },
    },
    {
      fieldName: 'bookingOrderId',
      label: '预约订单ID',
      rules: 'required',
      component: 'Input',
      componentProps: {
        placeholder: '请输入预约订单ID',
      },
    },
    {
      fieldName: 'orderDetailId',
      label: '订单明细ID',
      component: 'Input',
      componentProps: {
        placeholder: '请输入订单明细ID',
      },
    },
    {
      fieldName: 'resourceRequirementId',
      label: '资源需求ID',
      component: 'Input',
      componentProps: {
        placeholder: '请输入资源需求ID',
      },
    },
    {
      fieldName: 'checkPhase',
      label: '检查阶段',
      rules: 'required',
      component: 'Input',
      componentProps: {
        placeholder: '请输入检查阶段',
      },
    },
    {
      fieldName: 'checkType',
      label: '检查类型',
      rules: 'required',
      component: 'Select',
      componentProps: {
        options: getDictOptions(DICT_SPA_TYPE.SPA_Settlement_Status, 'string'),
        placeholder: '请选择检查类型',
      },
    },
    {
      fieldName: 'checkStatus',
      label: '检查状态',
      rules: 'required',
      component: 'RadioGroup',
      componentProps: {
        options: getDictOptions(DICT_SPA_TYPE.SPA_Settlement_Status, 'string'),
        buttonStyle: 'solid',
        optionType: 'button',
      },
    },
    {
      fieldName: 'checkTime',
      label: '检查时间',
      rules: 'required',
      component: 'DatePicker',
      componentProps: {
        showTime: true,
        format: 'YYYY-MM-DD HH:mm:ss',
        valueFormat: 'x',
      },
    },
    {
      fieldName: 'checkerId',
      label: '检查人ID',
      component: 'Input',
      componentProps: {
        placeholder: '请输入检查人ID',
      },
    },
    {
      fieldName: 'checkResult',
      label: '检查结果详情',
      component: 'Input',
      componentProps: {
        placeholder: '请输入检查结果详情',
      },
    },
    {
      fieldName: 'violationDetails',
      label: '违反详情',
      component: 'Input',
      componentProps: {
        placeholder: '请输入违反详情',
      },
    },
    {
      fieldName: 'suggestedSolutions',
      label: '建议解决方案',
      component: 'Input',
      componentProps: {
        placeholder: '请输入建议解决方案',
      },
    },
    {
      fieldName: 'resolutionStatus',
      label: '处理状态',
      component: 'RadioGroup',
      componentProps: {
        options: getDictOptions(DICT_SPA_TYPE.SPA_Settlement_Status, 'string'),
        buttonStyle: 'solid',
        optionType: 'button',
      },
    },
    {
      fieldName: 'resolutionAction',
      label: '处理动作',
      component: 'Input',
      componentProps: {
        placeholder: '请输入处理动作',
      },
    },
    {
      fieldName: 'resolutionNotes',
      label: '处理备注',
      component: 'Input',
      componentProps: {
        placeholder: '请输入处理备注',
      },
    },
    {
      fieldName: 'resolutionTime',
      label: '处理时间',
      component: 'DatePicker',
      componentProps: {
        showTime: true,
        format: 'YYYY-MM-DD HH:mm:ss',
        valueFormat: 'x',
      },
    },
    {
      fieldName: 'resolverId',
      label: '处理人ID',
      component: 'Input',
      componentProps: {
        placeholder: '请输入处理人ID',
      },
    },
  ];
}

/** 列表的搜索表单 */
export function useGridFormSchema(): VbenFormSchema[] {
  return [
    {
      fieldName: 'bookingOrderId',
      label: '预约订单ID',
      component: 'Input',
      componentProps: {
        allowClear: true,
        placeholder: '请输入预约订单ID',
      },
    },
    {
      fieldName: 'orderDetailId',
      label: '订单明细ID',
      component: 'Input',
      componentProps: {
        allowClear: true,
        placeholder: '请输入订单明细ID',
      },
    },
    {
      fieldName: 'resourceRequirementId',
      label: '资源需求ID',
      component: 'Input',
      componentProps: {
        allowClear: true,
        placeholder: '请输入资源需求ID',
      },
    },
    {
      fieldName: 'checkPhase',
      label: '检查阶段',
      component: 'Input',
      componentProps: {
        allowClear: true,
        placeholder: '请输入检查阶段',
      },
    },
    {
      fieldName: 'checkType',
      label: '检查类型',
      component: 'Select',
      componentProps: {
        allowClear: true,
        options: getDictOptions(DICT_SPA_TYPE.SPA_Settlement_Status, 'string'),
        placeholder: '请选择检查类型',
      },
    },
    {
      fieldName: 'checkStatus',
      label: '检查状态',
      component: 'Select',
      componentProps: {
        allowClear: true,
        options: getDictOptions(DICT_SPA_TYPE.SPA_Settlement_Status, 'string'),
        placeholder: '请选择检查状态',
      },
    },
    {
      fieldName: 'checkTime',
      label: '检查时间',
      component: 'RangePicker',
      componentProps: {
        ...getRangePickerDefaultProps(),
        allowClear: true,
      },
    },
    {
      fieldName: 'checkerId',
      label: '检查人ID',
      component: 'Input',
      componentProps: {
        allowClear: true,
        placeholder: '请输入检查人ID',
      },
    },
    {
      fieldName: 'checkResult',
      label: '检查结果详情',
      component: 'Input',
      componentProps: {
        allowClear: true,
        placeholder: '请输入检查结果详情',
      },
    },
    {
      fieldName: 'violationDetails',
      label: '违反详情',
      component: 'Input',
      componentProps: {
        allowClear: true,
        placeholder: '请输入违反详情',
      },
    },
    {
      fieldName: 'suggestedSolutions',
      label: '建议解决方案',
      component: 'Input',
      componentProps: {
        allowClear: true,
        placeholder: '请输入建议解决方案',
      },
    },
    {
      fieldName: 'resolutionStatus',
      label: '处理状态',
      component: 'Select',
      componentProps: {
        allowClear: true,
        options: getDictOptions(DICT_SPA_TYPE.SPA_Settlement_Status, 'string'),
        placeholder: '请选择处理状态',
      },
    },
    {
      fieldName: 'resolutionAction',
      label: '处理动作',
      component: 'Input',
      componentProps: {
        allowClear: true,
        placeholder: '请输入处理动作',
      },
    },
    {
      fieldName: 'resolutionNotes',
      label: '处理备注',
      component: 'Input',
      componentProps: {
        allowClear: true,
        placeholder: '请输入处理备注',
      },
    },
    {
      fieldName: 'resolutionTime',
      label: '处理时间',
      component: 'RangePicker',
      componentProps: {
        ...getRangePickerDefaultProps(),
        allowClear: true,
      },
    },
    {
      fieldName: 'resolverId',
      label: '处理人ID',
      component: 'Input',
      componentProps: {
        allowClear: true,
        placeholder: '请输入处理人ID',
      },
    },
    {
      fieldName: 'createTime',
      label: '创建时间',
      component: 'RangePicker',
      componentProps: {
        ...getRangePickerDefaultProps(),
        allowClear: true,
      },
    },
  ];
}

/** 列表的字段 */
export function useGridColumns(): VxeTableGridOptions<BookingResourceConstraintCheckApi.BookingResourceConstraintCheck>['columns'] {
  return [
    {
      field: 'id',
      title: '约束检查记录ID',
      minWidth: 120,
    },
    {
      field: 'bookingOrderId',
      title: '预约订单ID',
      minWidth: 120,
    },
    {
      field: 'orderDetailId',
      title: '订单明细ID',
      minWidth: 120,
    },
    {
      field: 'resourceRequirementId',
      title: '资源需求ID',
      minWidth: 120,
    },
    {
      field: 'checkPhase',
      title: '检查阶段',
      minWidth: 120,
    },
    {
      field: 'checkType',
      title: '检查类型',
      minWidth: 120,
    },
    {
      field: 'checkStatus',
      title: '检查状态',
      minWidth: 120,
    },
    {
      field: 'checkTime',
      title: '检查时间',
      minWidth: 120,
      formatter: 'formatDateTime',
    },
    {
      field: 'checkerId',
      title: '检查人ID',
      minWidth: 120,
    },
    {
      field: 'checkResult',
      title: '检查结果详情',
      minWidth: 120,
    },
    {
      field: 'violationDetails',
      title: '违反详情',
      minWidth: 120,
    },
    {
      field: 'suggestedSolutions',
      title: '建议解决方案',
      minWidth: 120,
    },
    {
      field: 'resolutionStatus',
      title: '处理状态',
      minWidth: 120,
    },
    {
      field: 'resolutionAction',
      title: '处理动作',
      minWidth: 120,
    },
    {
      field: 'resolutionNotes',
      title: '处理备注',
      minWidth: 120,
    },
    {
      field: 'resolutionTime',
      title: '处理时间',
      minWidth: 120,
      formatter: 'formatDateTime',
    },
    {
      field: 'resolverId',
      title: '处理人ID',
      minWidth: 120,
    },
    {
      field: 'createTime',
      title: '创建时间',
      minWidth: 120,
      formatter: 'formatDateTime',
    },
    {
      title: '操作',
      width: 200,
      fixed: 'right',
      slots: { default: 'actions' },
    },
  ];
}
